//
//  MemorandumShowViewController.m
//  ActionsMemorandum
//
//  Created by _LJX on 2017/10/26.
//  Copyright © 2017年 _LJX. All rights reserved.
//

#import "MemorandumShowViewController.h"
#import "SingleModle.h"
#import "MemorandumModle.h"
#import "UploadData.h"
@interface MemorandumShowViewController ()
@property (weak, nonatomic) IBOutlet UITextView *article;
@property (weak, nonatomic) IBOutlet UILabel *time;

@end

@implementation MemorandumShowViewController


- (IBAction)back:(id)sender {
   
    if([SingleModle shareData].cutternMem.article!=_article.text){
        NSLog(@"有修改");
        NSDate *currentDate = [NSDate date];
        //用于格式化NSDate对象
        NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
        //设置格式：zzz表示时区
        [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm"];
        //NSDate转NSString
        NSString *time = [dateFormatter stringFromDate:currentDate];
        
        NSInteger i = [_article.text length];
        if(i<15){
            i = i;
        }
        else{
            i = 15;
        }
        NSString *title =[_article.text substringWithRange:NSMakeRange(0, i)];
        NSLog(@"文章标题%@",title);
        NSDictionary *dic = [[NSDictionary alloc]initWithObjectsAndKeys:title,@"title",_article.text,@"article",time,@"time",nil];
        [[SingleModle shareData].mArr replaceObjectAtIndex:[SingleModle shareData].cutternIndex withObject:dic];
        [SingleModle shareData].DataCache = [SingleModle shareData].mArr;
        [UploadData WriteData];
    }
    else{
        
        NSLog(@"无修改!");
    }
    [self dismissViewControllerAnimated:YES completion:nil];
}










- (void)viewDidLoad {
    [super viewDidLoad];
//    NSInteger a = [SingleModle shareData].cutternIndex;
//    _article.text = [SingleModle shareData].cutternMem.article;
    
    [_article setText:[SingleModle shareData].cutternMem.article];
    _time.text = [SingleModle shareData].cutternMem.time;
    NSLog(@"%@",[SingleModle shareData].cutternMem.article);
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
